import socket

# 创建套接字
server = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
server.bind(("localhost", 9001))  # 绑定地址和端口
print("udp server已启动，接收数据中...")
while True:
    data, addr = server.recvfrom(1024)  # 接收客户端的请求，最大1024字节
    print(">>", data.decode())
    if not data:
        break
    server.sendto(data, addr)  # 向客户端发送数据

server.close()  # 关闭套接字



